package de.tabuma.customer.view;

import de.tabuma.lib.tabumaview;
import de.tabuma.customer.*;
import de.tabuma.customer.entity.*;
import java.io.PrintWriter;
import java.util.*;
import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 *
 * @author alefen
 */
public class updateView extends tabumaview {

    public updateView(String servlet, Hashtable parameter) {
        super(servlet, parameter);
    }

    public void processRequest(ServletContext context, HttpServletRequest request, HttpServletResponse response, PrintWriter out) {

        Customer customer = (Customer) request.getAttribute(constants.paramCustomer);
        String updateContent = "Update customer.";
        String customerName = "costumer name";
        String add = "Update";
        String back = "Back";
        out.println("<form action=\""+this.getServlet()+"\">");
        out.println("<div class=\"contentContent\">");
        out.println(updateContent);
        out.println("</div>");
        out.println("<div class=\"contentContent\">");
        out.println("<div class=\"col1\">");
        out.println("<div class=\"col1_head\">"+customerName+"</div>");
        out.println("<div class=\"col1_content\"><input type=\"text\" name=\""+constants.customerFieldName+"\" value=\""+customer.getName()+"\"/></div>");
        out.println("</div>");
        out.println("<div class=\"col2\"></div>");
        out.println("</div>");
        out.println("<div class=\"contentContent\">");
        Enumeration enu = this.getParameter().keys();
        while(enu.hasMoreElements()) {
            String key = (String) enu.nextElement();
            String value = (String) this.getParameter().get(key);
            out.println("<input type=\"hidden\" name=\""+key+"\" value=\""+value+"\"/>");
        }
        out.println("<input type=\"hidden\" name=\""+constants.paramId+"\" value=\""+customer.getId()+"\"/>");
        out.println("<input type=\"hidden\" name=\""+constants.paramName+"\" value=\""+constants.ACTION_UPDATE+"\"/>");
        out.println("<input type=\"hidden\" name=\""+constants.paramUpdate+"\" value=\"true\"/>");
        out.println("<input type=\"submit\" class=\"button\" value=\""+add+"\"/>");
        out.println("<input type=\"button\" class=\"button\" value=\""+back+"\" onClick=\"javascript:history.back()\"/>");
        out.println("</div>");
        out.println("</form>");

    }
    
}
